<template>
  <div>
    <Navbar appTitle="水位管理" />
    <div class="search-content wrap-apply" :style="{top: GLOBAL.currentEnvironment ? '0' : '',height: GLOBAL.currentEnvironment ? 'calc(100vh - 0.66rem' : 'calc(100vh - 1.12rem)'}">
      <van-cell-group>
        <p class="label required FormTit"><span></span>安全库存（{{manageForm.assistUnit}}）</p>
        <van-field v-model="manageForm.securityNum" @input="checkNum('securityNum')" placeholder="请输入" />
        <div class="bottomLine"></div>
      </van-cell-group>
      <van-cell-group>
        <p class="label required FormTit"><span></span>最大库存（{{manageForm.assistUnit}}）</p>
        <van-field v-model="manageForm.maxNum" @input="checkNum('maxNum')" placeholder="请输入" />
        <div class="bottomLine"></div>
      </van-cell-group>
      <div class="search-bottom">
        <!-- <span class="btnconfirm" @click="btnConfirm">确定</span> -->
        <van-button type="info" :loading="loadingSubmit" class="btnconfirm" loading-text="提交中..." @click="btnConfirm">提交</van-button>
      </div>
    </div>
  </div>
</template>
<script>
import Navbar from "@/components/navBar/navBar_right";
import { wmsGoodsWaterLevelEdit, wmsGoodsWaterLevelAdd } from '@/api/system'
import { clearNoNum } from '@/utils/util'
export default {
  name: "materialRequisitionForm", //领料单
  components: {
    Navbar,
  },

  data() {
    return {
      manageForm: {},
      loadingSubmit: false
    };
  },
  computed: {},
  mounted() {},
  created() {
    let obj = this.$route.query.info
    obj = JSON.parse(obj)
    this.manageForm = {
      goodsId: obj.goodsId,
      maxNum: obj.maxNum,
      securityNum: obj.securityNum,
      assistUnit: obj.assistUnit,
    }
    if (obj.id) {
      this.manageForm.id = obj.id
    }
  },
  methods: {
    checkNum(key) {
      this.manageForm[key] = clearNoNum(this.manageForm[key])
    },
    // 表单提交
    btnConfirm() {
      if (!this.manageForm.securityNum) {
        this.$toast('请输入安全库存')
        return
      }
      if (!this.manageForm.maxNum) {
        this.$toast('请输入最大库存')
        return
      }
      let requestApi = this.manageForm.id ? wmsGoodsWaterLevelEdit : wmsGoodsWaterLevelAdd
      this.loadingSubmit = true
      requestApi(this.manageForm).then(res => {
        if (res.code == 200) {
          this.$toast(res.message)
          this.$router.go(-1)
        } else {
          this.$toast(res.message)
        }
        this.loadingSubmit = false
      })
    },
  },
};
</script>
<style lang="scss" scoped>
@import "@/assets/theme.scss";
@import "@/views/workManagement/materialRequisition/materialForm.scss";
</style>
